import axios from 'axios';
import type { RouteRecordNormalized } from 'vue-router';
import { UserContext } from '@/types/api/user';

export interface LoginData {
  username: string;
  password: string;
}

export interface LoginRes {
  token: string;
}

export interface WxLoginRes {
  loginType: number;
  qrCode: string;
  key: string;
}

export function login(data: LoginData) {
  return axios.post<LoginRes>('/sys/login', data);
}

export function randomImage(key: string) {
  return axios.get<string>('/sys/randomImage', { params: { key } });
}

export function logout() {
  return axios.post<LoginRes>('/sys/logout');
}

export function getUserInfo() {
  return axios.post<UserContext>('/sys/user/info');
}

export function getMenuList() {
  return axios.post<RouteRecordNormalized[]>('/api/user/menu');
}

export function getWxLoginQrCode(key: string) {
  return axios.get<WxLoginRes>('/sys/getWxQrCode', {
    params: { key },
  });
}
